package me.linczh.bank.action;

import java.util.List;

import me.linczh.bank.bean.EmployeeBean;
import me.linczh.bank.bean.enums.Department;
import me.linczh.bank.bean.enums.Position;
import me.linczh.bank.bean.enums.ResultType;
import me.linczh.bank.service.EmployeeService;
import me.linczh.framework.action.ActionExecutor;

public class EmployeeAction extends ActionExecutor {
	private String username;
	private String password;
	private String employee;
	private String confirm;
	private String department;
	private String position;
	
	private List<EmployeeBean> employees;
	private EmployeeBean employeeBean;
	private ResultType result;
	
	public String login() {
		EmployeeService employeeService = new EmployeeService();
		EmployeeBean user = employeeService.getEmployee(username, password);
		if (user != null) {
			super.session.setAttribute("user", user);
			return "success";
		}
		return "invalid";
	}
	
	public String logout() {
		super.session.removeAttribute("user");
		return "success";
	}
	
	public String query() {
		EmployeeService employeeService = new EmployeeService();
		employees = employeeService.getAllEmployee();
		return "success";
	}
	
	public String create() {
		EmployeeService employeeService = new EmployeeService();
		try {
			Department d = Department.valueOf(department);
			Position p = Position.valueOf(position);
			employeeBean = employeeService.createEmployee(username, password, d, p);
			if (employeeBean == null) ;//result = ResultType;
			else result = ResultType.SUCCESS;
		} catch (IllegalArgumentException e) {
			result = ResultType.INVALID_INPUT_ENUM;
		}
		return "success";
	}
	
	public String delete() {
		EmployeeService employeeService = new EmployeeService();
		employeeService.deleteEmployee(employee);
		employees = employeeService.getAllEmployee();
		return "success";
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getEmployee() {
		return employee;
	}

	public void setEmployee(String employee) {
		this.employee = employee;
	}

	public String getConfirm() {
		return confirm;
	}

	public void setConfirm(String confirm) {
		this.confirm = confirm;
	}

	public String getDepartment() {
		return department;
	}

	public void setDepartment(String department) {
		this.department = department;
	}

	public String getPosition() {
		return position;
	}

	public void setPosition(String position) {
		this.position = position;
	}

	public EmployeeBean getEmployeeBean() {
		return employeeBean;
	}

	public void setEmployeeBean(EmployeeBean employeeBean) {
		this.employeeBean = employeeBean;
	}

	public ResultType getResult() {
		return result;
	}

	public void setResult(ResultType result) {
		this.result = result;
	}

	public List<EmployeeBean> getEmployees() {
		return employees;
	}

	public void setEmployees(List<EmployeeBean> employees) {
		this.employees = employees;
	}
	
}
